package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;

    /**
     * 供应商添加或修改
     * @param supplier
     */
//    @Override
//    public void save(String supplierName, String contacts, String phoneNumber, String address, String remarks) {
//        supplierDao.save(supplierName,contacts,phoneNumber,address,remarks);
//    }
    @Override
    public void save(Supplier supplier) {
        if (supplier.getSupplierId() != null){
            supplierDao.UpdateSupplierById(supplier);
        }else {
            supplierDao.save(supplier);
        }

    }

    /**
     * 删除供应商（支持批量删除）
     * @param ids
     */
    @Override
    public void deleteSupplierById(String ids) {

        String[] id = ids.split(",");
        for (String s : id) {
            supplierDao.deleteSupplierById(s);
        }

    }

    /**
     * 分页查询供应商
     * @param supplierName
     * @return
     */
    @Override
    public List<Supplier> list(String supplierName) {
        return supplierDao.selectSupplierPage(supplierName);
    }




}
